//Copyright (c) 2010, Goodwine & Tibia ML
//Licensed under new BSD License.

// Adds a '[Set as Default]' for a default character for posting.
var selec = document.getElementsByName("forum_character");
selec = selec[0];
// Inject script to read the ID of the char and save it in localStorage.
if(selec != null)
{
	var link = document.createElement('a');
	link.href = "javascript:;";
	link.innerText = "[Set as Default]";
	link.onclick = function() {
		try{
			localStorage.setItem('defaultChar', selec.value);
			alert(selec.options[selec.selectedIndex].text+' was set as default.');
		}
		catch(e)
		{ alert('An error ocurred, '+selec.options[selec.selectedIndex].text+' was not set as default, if problems persists, contact the developer'); }
	};
	var span = document.createElement('span');
	span.innerText = ' ';
	span.appendChild(link);
	selec.parentNode.appendChild(span);
	if(localStorage.getItem('defaultChar') != null)
	{
		var selec = document.getElementsByName('forum_character');
		selec = selec[0];
		for(var i = 0; i < selec.options.length; i++)
		{
			if(selec.options[i].value == localStorage.getItem('defaultChar'))
			{
				selec.selectedIndex = i;
				break;
			}
		}
	}
}

// Removes "Parse URL by Default"

var forumParseURLOption = document.getElementsByName('forum_option_autourl')[0].parentElement;
forumParseURLOption.innerHTML = forumParseURLOption.innerHTML.replace(/^.*?name="forum_option_autourl".*?<br>/ig,'<input type="hidden" name="forum_option_autourl" value=0>');